fix: resolve double LIMIT bug in SQL pagination wrapping#154
Merged
debba merged 1 commit intoTabularisDB:mainfrom May 4, 2026
Merged
fix: resolve double LIMIT bug in SQL pagination wrapping#154debba merged 1 commit intoTabularisDB:mainfrom
debba merged 1 commit intoTabularisDB:mainfrom
Conversation
The `strip_limit_offset` and `extract_user_limit` helpers used naive
`rfind("LIMIT")` / `rfind("OFFSET")` which matched the keyword as a
substring of table names (e.g. `tapp_appointment_message_event_limit`),
string literals, or quoted identifiers — producing corrupted pagination
queries.
Replace the raw string search with a quote-and-bracket-aware SQL
tokenizer (`tokenize_sql`) that treats single-quoted strings,
double-quoted identifiers, backtick-quoted identifiers, and
parenthesized groups as opaque tokens. `strip_limit_offset` and
`extract_user_limit` now scan backward over tokens so only standalone
`LIMIT` / `OFFSET` keywords are matched.
Also update MCP `run_query` tool:
- Accept an optional `limit` parameter (default 100)
- Document that user LIMIT clauses in the SQL are respected
Add 11 new test cases covering table names containing "limit", quoted
identifiers, string literals with SQL keywords, and subqueries.
Made-with: Cursor
b9d81bf to
c4d2298
Compare
Collaborator
|
Thanks for PR, I will check it ASAP |
Collaborator
|
i will merge it, thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_order_by/remove_order_byused naiverfind("ORDER BY")that captured trailing LIMIT/OFFSET clauses, producing double LIMIT syntax errors when the pagination layer appended its own LIMIT.extract_trailing_clauses+build_paginated_query) indrivers/common.rsthat correctly separates ORDER BY, LIMIT, and OFFSET from the base query.run_querynow accepts an optionallimitparameter and respects user-specified LIMIT clauses (takesmin(user_limit, page_size)).Bug details
When a user (or AI agent via MCP) ran a query like:
The old code produced invalid SQL:
The double
LIMIT 10 LIMIT 101is a syntax error on all database engines.Changes
src-tauri/src/drivers/common.rstokenize_sql,extract_trailing_clauses,build_paginated_query+ 18 unit testssrc-tauri/src/drivers/postgres/mod.rssrc-tauri/src/drivers/mysql/mod.rssrc-tauri/src/drivers/sqlite/mod.rssrc-tauri/src/mcp/mod.rslimitparam torun_query, use configurable max_rowsTest plan
cargo test --lib drivers::common::tests) covering:tapp_appointment_message_event_limit)build_paginated_querywith user limit smaller/larger than page_sizecargo test --libpasses (115/117 pass; 2 pre-existing failures inupdater::testsunrelated to this change)cargo buildsucceeds with no warnings